/***
 * 通过new server类实例创建net服务器
 */

var net = require('net');
var server = new net.Server();
var os = require('os');

server.listen(8124,function(){
    console.log(os.cpus());
    console.log("监听8124")

})

server.on('connection',function(socket){
    console.log("--------------------------------")
    console.log("连接上一个客户端")
    
    socket.on('data',function(data){
        var  remoteIp = socket.remoteAddress;
        console.log("接收到： " + remoteIp  + data.toString());
        socket.write("服务器回复数据");
    });
    socket.on('end',function(){
        console.log("结束了");
    });
    
})

server.on('close',function(){
    console.log("断开连接")
})